"use client"
import React, { useState,useEffect } from 'react';
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from 'antd';

interface propsTs {
  title: string,
  itemobj?: any,
  onSuccess: (values: any, isEdit: boolean) => void;
  onCancel: () => void
}
const Formlist = (props:propsTs) => {
  const [form] = Form.useForm();
  useEffect(() => {
    if(props.title=="编辑"){
      form.setFieldsValue(props.itemobj);
    }
  }, []);
  const onFinish = (values: any) => {
    console.log(values)
    if (props.title === '添加') {
      const newItem = {
          id: new Date().getTime(), // 生成唯一ID
          ...values
      };
      props.onSuccess(newItem, false);
  } else if (props.title == '编辑') {
      const obj = {
          ...props.itemobj,
          ...values
      };
      props.onSuccess(obj, true);
  }
  };
  return (
    <Form
    onFinish={onFinish}
    form={form}
    >
      <Form.Item
      label="关联客户"
      name="address"
      rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item
      label="客户状态"
      name="Collect">
        <Switch />
      </Form.Item>
      <Form.Item
      label="星级客户"
      name="start"
      rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item
      label="首联系人"
      name="title"
      rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item
      label="手机号码"
      name="phone"
      rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item
      label="未跟进天数"
      name="day"
      rules={[{ required: true, message: 'Please input your username!' }]}>
        <Input />
      </Form.Item>
      <Form.Item>
        <Button  type="primary" htmlType="submit">Button</Button>
      </Form.Item>
    </Form>
  );
};

export default Formlist;